<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:p="http://primefaces.prime.com.tr/ui"
	template="/templates/admin-template-html5-css3/decorator.xhtml">

	<ui:define name="titulo">
		<h:outputText value="#{msg.listar} #{msg.arquivos}" />
	</ui:define>

	<ui:define name="alertas">
		<h:form id="alertas">
			<h:outputText value="${arquivoFace.errorMessages}" />
			<h:messages showDetail="#{true}" showSummary="#{false}" />
		</h:form>
	</ui:define>
	
	<ui:define name="breadcrumbs">
		<h:form id="breadcrumbs">
			<h:outputText value="${arquivoFace.migalhas}" />
		</h:form>
	</ui:define>

	<ui:define name="mensagens">
		<h:outputText value="${arquivoFace.resultado}" />
	</ui:define>

	<ui:define name="conteudo">
	</ui:define>
	
	<ui:define name="listing">
		<h2 class="title"><h:outputText value="#{msg.listar} #{msg.arquivos}" /></h2>

		<h:form id="listagem">

			<p:dataTable var="item" value="#{arquivoFace.listaPojosCacheados}"
				paginator="true" rows="3" dynamic="true"
				loadingMessage="Carregando informações..."
				rendered="#{!empty arquivoFace.listaPojosCacheados}"
				styleClass="listing" headerClass="cabecalhoTabela" rowClasses="linhaPar,linhaImpar"
				firstPageLinkLabel="#{msg.primeiro}"
				previousPageLinkLabel="#{msg.anterior}"
				nextPageLinkLabel="#{msg.proximo}" lastPageLinkLabel="#{msg.ultimo}">
				<p:column>
					<f:facet name="header">
						<h:outputText value="ID" />
					</f:facet>
					<h:outputText value="#{item.id}" />
				</p:column>

				<p:column sortBy="#{item.nome}">
					<f:facet name="header">
						<h:outputText value="Nome" />
					</f:facet>
					<h:outputText value="#{item.nome}" />
				</p:column>

				<p:column sortBy="#{item.dataCriacao}">
					<f:facet name="header">
						<h:outputText value="Data de Criação" />
					</f:facet>
					<h:outputText value="#{item.dataCriacao}">
						<f:convertDateTime pattern="dd/MM/yyyy" />
					</h:outputText>
				</p:column>
				
				<p:column sortBy="#{item.dataAlteracao}">
					<f:facet name="header">
						<h:outputText value="Data de Alteração" />
					</f:facet>
					<h:outputText value="#{item.dataAlteracao}">
						<f:convertDateTime pattern="dd/MM/yyyy" />
					</h:outputText>
				</p:column>
				
				<p:column sortBy="#{item.dataRemocao}">
					<f:facet name="header">
						<h:outputText value="Data de Remoção" />
					</f:facet>
					<h:outputText value="#{item.dataRemocao}">
						<f:convertDateTime pattern="dd/MM/yyyy" />
					</h:outputText>
				</p:column>

				<p:column>
					<f:facet name="header">
						<h:outputText value="Publico?" />
					</f:facet>
					<h:outputText value="#{item.publico}" />
				</p:column>

				<p:column>
					<f:facet name="header">
						<h:outputText value="#{msg.editar}" />
					</f:facet>
					<h:commandLink>
						<f:setPropertyActionListener value="#{item}"
							target="#{arquivoFace.pojoSelecionado}" />
						<h:graphicImage style="border: 0px; align: center;"
							alt="#{msg.editar}" library="images" name="botao_editar.gif">
						</h:graphicImage>
						<f:ajax execute="@this" render=":formulario" />
					</h:commandLink>
				</p:column>
				<p:column>
					<f:facet name="header">
						<h:outputText value="#{msg.excluir}" />
					</f:facet>
					<h:commandLink action="#{arquivoFace.excluir}">
						<f:setPropertyActionListener value="#{item}"
							target="#{arquivoFace.pojoSelecionado}" />
						<h:graphicImage style="border: 0px; align: center;"
							alt="#{msg.excluir}" library="images" name="botao_remover.gif">
						</h:graphicImage>
						<f:ajax execute="@this" render=":listagem :alertas" />
					</h:commandLink>
				</p:column>

			</p:dataTable>
			
			<h:panelGrid columns="3" cellpadding="5" id="botoes">
				<h:commandButton value="Export as Excel">
					<p:dataExporter type="xls" target="idTabela" fileName="arquivos.xls" />
				</h:commandButton>
				<h:commandButton value="Export as PDF">
					<p:dataExporter type="pdf" target="idTabela" fileName="arquivos.dpf" />
				</h:commandButton>
				<h:commandButton value="Export as PDF page only">
					<p:dataExporter type="pdf" target="idTabela" fileName="arquivos.dpf"
						pageOnly="true" />
				</h:commandButton>
		</h:panelGrid>
		</h:form>
	</ui:define>
	
	<ui:define name="listing-form">
		<h:form id="formulario" enctype="multipart/form-data">
			<h:inputHidden id="id" value="#{arquivoFace.pojoSelecionado.id}" />
			<h2 class="title">
				<h:outputText value="#{msg.cadastrar} #{msg.arquivo}" rendered="#{empty arquivoFace.pojoSelecionado.id}" />
				<h:outputText value="#{msg.alterar} #{msg.arquivo}" rendered="#{!empty arquivoFace.pojoSelecionado.id}" />
			</h2>

			<h:panelGrid columns="3" cellpadding="0" border="0" 
				styleClass="listing form"
				columnClasses="listing form"
				headerClass="full">

				<h:outputText value="Nome: " />
				<h:inputText id="nome" label="Campo Nome" styleClass="text"
					value="#{arquivoFace.pojoSelecionado.nome}" required="false"
					requiredMessage="#{msg.INPUT_REQUIRED}" immediate="true" />
				<h:message id="avisoNome" for="nome" styleClass="AVISO" />
				
				<h:outputText value="Arquivo: " />
				<h:inputFile id="upload" label="Campo Arquivo" styleClass="text"
					value="#{arquivoFace.file}" storage="file" required="true" 
					requiredMessage="#{msg.INPUT_REQUIRED}" immediate="true" />
				<h:message id="avisoUpload" for="upload" styleClass="AVISO" />

				<h:outputText value="Data de Criação: " />
				<h:inputText id="dataCriacao" label="Campo Data de Criação" 
					value="#{arquivoFace.pojoSelecionado.dataCriacao}"
					requiredMessage="#{msg.INPUT_REQUIRED}" styleClass="text"
					required="true">
					<f:convertDateTime pattern="dd/MM/yyyy" />
				</h:inputText>
				<h:message id="avisoDataCriacao" for="dataCriacao"
					styleClass="AVISO" />
				
				<h:outputText value="Data de Alteração: " />
				<h:inputText id="dataAlteracao" label="Campo Data de Alteração"
					value="#{arquivoFace.pojoSelecionado.dataAlteracao}"
					requiredMessage="#{msg.INPUT_REQUIRED}" styleClass="text data"
					required="false">
					<f:convertDateTime pattern="dd/MM/yyyy" />
				</h:inputText>
				<h:message id="avisoDataAlteracao" for="dataAlteracao"
					styleClass="AVISO" />
					
				<h:outputText value="Data de Remoção: " />
				<h:inputText id="dataRemocao" label="Campo Data de Remoção"
					value="#{arquivoFace.pojoSelecionado.dataRemocao}"
					requiredMessage="#{msg.INPUT_REQUIRED}" styleClass="text data"
					required="false">
					<f:convertDateTime pattern="dd/MM/yyyy" />
				</h:inputText>
				<h:message id="avisoDataRemocao" for="dataRemocao"
					styleClass="AVISO" />

				<h:outputText value="Público?" />
				<h:selectOneRadio id="publico" border="1" layout="pageDirection"
					value="#{arquivoFace.pojoSelecionado.publico}">
					<f:selectItem id="itemSim" itemLabel="Sim" itemValue="SIM" />
					<f:selectItem id="itemNao" itemLabel="Não" itemValue="NÃO" />
				</h:selectOneRadio>
				<h:message id="avisoPublico" for="publico" styleClass="AVISO" />

				<h:outputText value="" />
				<h:outputText value="" />
				<h:commandButton actionListener="#{arquivoFace.salvar}" value="Salvar">
					<f:ajax execute="@form" render=":formulario :listagem :alertas" />
				</h:commandButton>
			</h:panelGrid>
		</h:form>
	</ui:define>
	
</ui:composition>